package com.itheima.deadlock;

import java.util.Objects;

/*
死锁
 */
public class Demo01 {


    public static void main(String[] args) {
        Object obja= new Object();
        Object objb = new Object();


        new Thread(()->{
            while (true){
                System.out.println("尔康在尝试获取a锁");
                synchronized (obja) {
                    System.out.println("尔康拿到a锁");
                    System.out.println("尔康在尝试获取b锁");
                    synchronized (objb) {
                        System.out.println("尔康拿到b锁");
                        System.out.println("尔康正在走路");
                        System.out.println("尔康释放b锁");
                    }
                    System.out.println("尔康释放a锁");
                }
            }
        }).start();

        new Thread(()->{
            while (true){
                System.out.println("紫薇在尝试获取b锁");
                synchronized (objb) {
                    System.out.println("紫薇拿到b锁");
                    System.out.println("紫薇在尝试获取a锁");
                    synchronized (obja) {
                        System.out.println("紫薇拿到a锁");
                        System.out.println("紫薇正在走路");
                        System.out.println("紫薇释放a锁");
                    }
                    System.out.println("紫薇释放b锁");
                }
            }
        }).start();
    }
}
